package com.ruoyi.tb.lmt.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.tb.lmt.domain.vo.TbLmttypeVo;
import com.ruoyi.tb.lmt.domain.bo.TbLmttypeBo;
import com.ruoyi.tb.lmt.service.ITbLmttypeService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 大机型号
 *
 * @author ruoyi
 * @date 2023-11-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xha-lmt/lmttype")
public class TbLmttypeController extends BaseController {

    private final ITbLmttypeService iTbLmttypeService;

    /**
     * 查询大机型号列表
     */
    //@SaCheckPermission("xha-lmt:lmttype:list")
    @GetMapping("/list")
    public TableDataInfo<TbLmttypeVo> list(TbLmttypeBo bo, PageQuery pageQuery) {
        return iTbLmttypeService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出大机型号列表
     */
    @SaCheckPermission("xha-lmt:lmttype:export")
    @Log(title = "大机型号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TbLmttypeBo bo, HttpServletResponse response) {
        List<TbLmttypeVo> list = iTbLmttypeService.queryList(bo);
        ExcelUtil.exportExcel(list, "大机型号", TbLmttypeVo.class, response);
    }

    /**
     * 获取大机型号详细信息
     *
     * @param ID 主键
     */
    @SaCheckPermission("xha-lmt:lmttype:query")
    @GetMapping("/{ID}")
    public R<TbLmttypeVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long ID) {
        return R.ok(iTbLmttypeService.queryById(ID));
    }

    /**
     * 新增大机型号
     */
    @SaCheckPermission("xha-lmt:lmttype:add")
    @Log(title = "大机型号", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TbLmttypeBo bo) {
        return toAjax(iTbLmttypeService.insertByBo(bo));
    }

    /**
     * 修改大机型号
     */
    @SaCheckPermission("xha-lmt:lmttype:edit")
    @Log(title = "大机型号", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TbLmttypeBo bo) {
        return toAjax(iTbLmttypeService.updateByBo(bo));
    }

    /**
     * 删除大机型号
     *
     * @param IDs 主键串
     */
    @SaCheckPermission("xha-lmt:lmttype:remove")
    @Log(title = "大机型号", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] IDs) {
        return toAjax(iTbLmttypeService.deleteWithValidByIds(Arrays.asList(IDs), true));
    }



}
